#include "esp_event.h"
#include "esp_log.h"
#include "esp_netif.h"
#include "esp_err.h"
#include "nvs_flash.h"
#include "stdio.h"
#include "read_bin.h"
#define TAG "fileread"

int GetBinSize(char *filename)  
{     
    int  siz = 0;     
    FILE  *fp = fopen(filename, "rb");     
    if (fp)   
    {        
        fseek(fp, 0, SEEK_END);        
        siz = ftell(fp);        
        fclose(fp);     
    }    
    ESP_LOGI(TAG,"\nfilename=%s,size=%d \n",filename,siz);	
    return siz;  
}
 
void read_bin(char *path, char *buf, int size)  
{  
    FILE *infile;  
      
    if((infile=fopen(path,"rb"))==NULL)  
    {  
        ESP_LOGI(TAG,"\nCan not open the path: %s \n", path);  
        exit(-1);  
    }  
    fread(buf, sizeof(char), size, infile);
    ESP_LOGI(TAG,"readfile OK!"); 
    fclose(infile);  
} 
 
void readbin(char* path,char* buf,int* size)
{
	struct fb_videomode *mode, *m;
	unsigned char *block;
	int i = 0;
    *size = GetBinSize(path);
	char edid_data[2048];	
	read_bin(path, edid_data,*size);  

	for(i=0;i<*size;i++)
	{	
        	    
		ESP_LOGI(TAG,"0x%02x,",edid_data[i]);//以二进制的格式输出
	}

	ESP_LOGI(TAG,"\nread edid completely!\n");
    return;
}
